package com.mk.legoscans2;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

public class GCMIntentService extends com.google.android.gcm.GCMBaseIntentService {

	public GCMIntentService(){
		super(LegoScans3Application.GCMSenderId);
	}
	
	@Override
	protected void onError(Context arg0, String arg1) {
		/*onError(Context context, String errorId): Called when the device tries to register or unregister, but GCM returned an error. Typically, there is nothing to be done other than evaluating the error (returned by errorId) and trying to fix the problem.*/
	}

	@Override
	protected void onMessage(Context arg0, Intent arg1) {
		/*onMessage(Context context, Intent intent): Called when your server sends a message to GCM, and GCM delivers it to the device. If the message has a payload, its contents are available as extras in the intent.*/
		
		Bundle extras = arg1.getExtras();
		String title = extras.getString("contentTitle");
		String message = extras.getString("message");
		
		LegoScans3Application.NotificationService.createNotification(this, title, message);
	}
	
	@Override
	protected void onRegistered(Context arg0, String arg1) {
		/*onRegistered(Context context, String regId): Called after a registration intent is received, passes the registration ID assigned by GCM to that device/application pair as parameter. Typically, you should send the regid to your server so it can use it to send messages to this device.*/
		
		LegoScans3Application.NotificationService.register(arg0, arg1, LegoScans3Application.AccountService.getAccount());
	}

	@Override
	protected void onUnregistered(Context arg0, String arg1) {
		/*onUnregistered(Context context, String regId): Called after the device has been unregistered from GCM. Typically, you should send the regid to the server so it unregisters the device.*/
		
		LegoScans3Application.NotificationService.unRegister(arg1);
	}
}
